//
//  AESubmitOrderViewController.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/14.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AESubmitOrderViewController.h"
#import "AE_Solar-Swift.h"
#import "AESubmitOrderViewModel.h"
#import "AESubmitOrderTopView.h"
#import "AESubmitOrderDeliveryWayView.h" // 派送方式
#import "AESubmitOrderCommonSectionView.h"
#import "AESubmitOrderBottomView.h"

@interface AESubmitOrderViewController ()

@property (nonatomic, strong) AESubmitOrderViewModel *viewModel;

@property (nonatomic, strong) AESubmitOrderTopView *topView;

/// 派送方式视图
@property (nonatomic, strong) AESubmitOrderDeliveryWayView *deliveryWayView;

/// 可用积分视图
@property (nonatomic, strong) AESubmitOrderCommonSectionView *availableIntegralView;

/// 支付视图
@property (nonatomic, strong) AESubmitOrderCommonSectionView *paymentView;

@property (nonatomic, strong) AESubmitOrderBottomView *bottomView;

@end

@implementation AESubmitOrderViewController

- (void)dealloc {
    debugMethod();
}

- (void)initWithVar {
    [super initWithVar];
    
}

- (void)initWithViewModel {
    _viewModel = [AESubmitOrderViewModel new];
    [_viewModel setupData];
}

- (void)initWithNavBar {
    [super initWithNavBar];
    
}

- (void)initWithSubView {
    [super initWithSubView];
    
    [self initWithTopView];
    
    [self initWithDeliveryWayView];
    
    /// 可用积分视图
    [self initWithAvailableIntegralView];
    
    /// 支付视图
    [self initWithPaymentView];
    
    [self initWithBottomView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)initWithTopView {
    if (!_topView) {
        CGRect frame = CGRectMake(0, 0, kScreenW, kAESubmitOrderTopViewHeight);
        _topView = [[AESubmitOrderTopView alloc] initWithFrame:frame];
        [self.view addSubview:_topView];
        
        @weakify(self);
        _topView.touchBackBlock = ^{
            @strongify(self);
            [self clickedBack:nil];
        };
    }
    [self.topView updateWithViewData:self.viewModel];
}

/// 派送方式
- (void)initWithDeliveryWayView {
    if (!_deliveryWayView) {
        CGRect frame = CGRectMake(10, self.topView.bottom, kScreenW - 20, kAESubmitOrderDeliveryWayViewHeight);
        _deliveryWayView = [[AESubmitOrderDeliveryWayView alloc] initWithFrame:frame];
        [self.view addSubview:_deliveryWayView];
    }
    [self.deliveryWayView updateWithViewData:self.viewModel];
}

/// 可用积分视图
- (void)initWithAvailableIntegralView {
    if (!_availableIntegralView) {
        CGRect frame = CGRectMake(10, self.deliveryWayView.bottom + 10, kScreenW - 20, kAESubmitOrderCommonSectionViewHeight);
        _availableIntegralView = [[AESubmitOrderCommonSectionView alloc] initWithFrame:frame];
        [self.view addSubview:_availableIntegralView];
    }
    NSString *title = [AEStringExten localizedValueWithKey:@"可用积分"];
    NSString *cnt = [AEStringExten localizedValueWithKey:@"积分"];
    NSString *value = [NSString stringWithFormat:@"%@%@", @"889", cnt];
    [self.availableIntegralView updateWithViewTitle:title value:value];
}

/// 支付视图
- (void)initWithPaymentView {
    if (!_paymentView) {
        CGRect frame = self.availableIntegralView.frame;
        frame.origin.y = self.availableIntegralView.bottom + 10;
        _paymentView = [[AESubmitOrderCommonSectionView alloc] initWithFrame:frame];
        [self.view addSubview:_paymentView];
    }
    
    NSString *title = [AEStringExten localizedValueWithKey:@"支付"];
    NSString *cnt = [AEStringExten localizedValueWithKey:@"积分支付"];
    NSString *value = [NSString stringWithFormat:@"%@%@", @"", cnt];
    [self.paymentView updateWithViewTitle:title value:value];
}

- (void)initWithBottomView {
    if (!_bottomView) {
        CGRect frame = CGRectMake(0, kScreenH - TABBAR_HEIGHT, kScreenW, kAESubmitOrderBottomViewHeight);
        _bottomView = [[AESubmitOrderBottomView alloc] initWithFrame:frame];
        [self.view addSubview:_bottomView];
        
        @weakify(self);
        _bottomView.touchSubmitOrderBlock = ^{
            @strongify(self);
            [self actionWithSubmitOrder];
        };
    }
    
    [self.bottomView updateWithViewData:self.viewModel];
}

/// 提交订单
- (void)actionWithSubmitOrder {
    [SVProgressHUD showInfoWithStatus:@"提交订单"];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}


@end
